#include "stdafx.h"

#include "readBaumerMex.h"

/// Release the camera system.
int release() {

	if (isInitialised) {
	
		/* bei Programmende Kamera stoppen: */
		for (int cam = 0; cam < camera_count; cam++) {
			res = pCamera[cam]->setStart( false );
			if( res != BGAPI_RESULT_OK )
			{
				printf("BGAPI::Camera::setStart for camera %d Errorcode: %d\n", cam, res );
				return BGAPI_RESULT_FAIL;
			}
		}
		
		
		/* System freigeben */
		res = pSystem->release();
		if( res != BGAPI_RESULT_OK )
		{
			printf( "BGAPI::System::release Errorcode: %d\n", res );
			return BGAPI_RESULT_FAIL;
		}

		/*printf("rebooting cameras.\n");
		pCamera[0]->doReboot();
		pCamera[1]->doReboot();*/

		free(imageBufferB0);
		free(imageBufferB1);
		
		isInitialised = false;
	} else {
		mexPrintf("Release: System is not initialised. No need to release.\n");
	}
	
	return BGAPI_RESULT_OK;
}

